package com.wyd.config;

import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisPoolConfig;

import java.util.LinkedHashSet;
import java.util.Set;

public class RedisTest {
  public static void main(String[] args) {
    JedisPoolConfig poolConfig = new JedisPoolConfig();
    // 最大连接数
    poolConfig.setMaxTotal(1);
    // 最大空闲数
    poolConfig.setMaxIdle(1);
    // 最大允许等待时间，如果超过这个时间还未获取到连接，则会报JedisException异常：
    // Could not get a resource from the pool
    poolConfig.setMaxWaitMillis(1000);
    Set<HostAndPort> nodes = new LinkedHashSet<HostAndPort>();
    nodes.add(new HostAndPort("192.168.10.207", 6381));
    nodes.add(new HostAndPort("192.168.10.207", 6382));
    nodes.add(new HostAndPort("192.168.10.207", 6383));
    nodes.add(new HostAndPort("192.168.10.207", 6384));
    nodes.add(new HostAndPort("192.168.10.207", 6385));
    nodes.add(new HostAndPort("192.168.10.207", 6386));
    JedisCluster cluster = new JedisCluster(nodes, 300, 3);
    cluster.set("test-one","test测试");
    String name = cluster.get("test-one");
    String name1 = cluster.get("082905024712911703");
    String value = cluster.hget("26713553", "60013783");
    System.out.println(name);
    System.out.println(name1);
    System.out.println(value);
    cluster.close();
  }

}